home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3036 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.9 KB  |  87 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!mv!usenet
  3. From: ENGR@GSSI.MV.COM (Michael Furman)
  4. Subject: Re: === Repost : Interrupt driven object ===
  5. Message-ID: <DLC7ux.LuL@mv.mv.com>
  6. Mime-Version: 1.0
  7. Organization: GSSI
  8. Date: Wed, 17 Jan 1996 18:11:21 GMT
  9. References: <4dj02s$60q@newsbf02.news.aol.com>
  10. X-Newsreader: WinVN 0.93.10
  11. X-Nntp-Posting-Host: gssi.mv.com
  12.  
  13. In article <4dj02s$60q@newsbf02.news.aol.com>, awhang8367@aol.com says...
  14. >
  15. >
  16. >>In article <4d6imm$okq@newsbf02.news.aol.com>, awhang8367@aol.com says...
  17. >>
  18. >>  I have been struggling to create an object that handles hardware
  19. >>interrupt directly. 
  20. >.... snip ....
  21.  
  22. I thought that I answered your question in my previous post. Probably I
  23. was not clear enough.
  24.  
  25. >
  26. >class serial_device:public UART
  27. >{
  28. >  private :
  29. >   .
  30. >   .
  31. >   .
  32. >   .
  33. >
  34. >  public :
  35. >  void interrupt far isr(...);
  36.  
  37. You can't use nonstatic member function as ISR because it takes additional
  38. hidden argument - pointer to class instance. And hardware interrupt mechanism
  39. and even OS can not provide it at the interrupt time (because nobody knows
  40. besides you).
  41.  
  42. If you are making class for working with just one interrupt you can write
  43. external interrupt interface static function and use static variable to pass
  44. pointer to class instance. It will look like:
  45.  
  46.   static serial_device * sdp;               // Static variable that holds
  47.                                             // pointer to only one instance
  48.                                             // of class
  49.   static void interrupt far ext_isr(......) // external ISR interface
  50.                                             // function
  51.     {
  52.     sdp->isr(......);         // Call your "ISR" function
  53.     }
  54.   void isr(....);             // Your "ISR" function
  55.   serial_device(....)
  56.     {
  57.     sdp = this;
  58.     .......
  59.     setvect(...., ext_isr);
  60.     .......
  61.     }
  62.   
  63. If you need to work with more than one device (using the same class) you need
  64. a different interface ISR function with different pointer to class instance
  65. for each interrupt. I know the only one way to do it - generate separate
  66. assembler stub - interface function with its own pointer for each class 
  67. instance (I described it a little bit more detailed in my previous post).  
  68.  
  69. Also - do not forget about stack. You do not know which stack will be active
  70. at the interrupt time - it may be DOS stack which is very small. If you
  71. ISR is more then a couple simple statements you HAVE to provide your own
  72. stack - interface function is a good place to switch it before call isr()
  73. and swinch it back after.
  74.  
  75. If you have further questions - let me know.
  76.  
  77.  
  78. <<<<< This is a copy of the post to newsgroup >>>>>>
  79. -- 
  80. ---------------------------------------------------------------
  81. Michael Furman,                       (603)893-1109
  82. Geophysical Survey Systems, Inc.  fax:(603)889-3984
  83. 13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
  84. North Salem, NH 03073-0097            71543.1334@compuserve.com
  85. ---------------------------------------------------------------
  86.  
  87.